﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Turtle8
{
    public partial class ExistsPostCardView : Form
    {
        SqlDataAdapter da;
        DataTable dt = new DataTable();
        TahasukaDuringPostCard postCard;

        public ExistsPostCardView(TahasukaDuringPostCard postCard, DateTime startDate)
        {
            InitializeComponent();

            this.postCard = postCard;

            da = new SqlDataAdapter(@"SELECT postName FROM [TahasukaPosts] WHERE startDate=@startDate", CompanyManager.Connection);
            da.SelectCommand.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;

            //if there aron current postCards in database set Dialog result to NO, else YES
            int i ;
            if ((i = da.Fill(dt)) == 0)
                this.DialogResult = DialogResult.No;
            else
            {
                dataGridView.DataSource = dt;
                dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                CompanyManager.setTableColumnHeadersHebrew(dataGridView.Columns);
                this.DialogResult = DialogResult.Yes;
            }
        }

        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            postCard.SelectedPostName =(string)dataGridView.Rows[e.RowIndex].Cells[0].Value;
            this.Dispose();
        }
    }
}
